<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('申请售后列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>电话：</label>
                                <input type="text" name="phone"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="0">待处理</option>
                                    <option value="1">通过</option>
                                    <option value="2">驳回</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>


            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('jiajia:shouHou:edit')}]];
        var removeFlag = [[${@permission.hasPermi('jiajia:shouHou:remove')}]];
        var prefix = ctx + "jiajia/shouHou";
        var orderPrefix = ctx + "jiajia/order";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "申请售后",
                columns: [
                {
                    field: '用户信息',
                    title: '用户信息',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push($.table.imageView(row.uAvatar))
                        actions.push("&nbsp;&nbsp;&nbsp;")
                        actions.push(row.uName)
                        actions.push("</br>");
                        actions.push("联系电话："+row.phone)
                        actions.push("</br>");
                        actions.push("项目名称:"+row.iName)
                        actions.push("</br>")
                        actions.push("申请时间:"+row.addtime);
                        return actions.join('');
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.status == 0){
                            actions.push("<span style='color: darkgreen'>待处理</span>")
                        }else if ((row.status == 1)){
                            actions.push("<span style='color: darkblue'>通过</span>")
                        }else {
                            actions.push("<span style='color: darkred'>驳回</span>")
                            actions.push("</br>")
                            actions.push("驳回原因:"+row.boHuiCause)
                        }
                        return actions.join('');
                    }
                },
                {
                    field: '订单号',
                    title: '订单号',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a style=\'text-decoration-line: underline;\' href="javascript:void(0)" onclick="goOrder(\'' + row.oid + '\')">'+row.orderSn+'</a> ');
                        // actions.push("<a style='text-decoration-line: underline;' onclick=\"goOrder(\\'' + row.oid + '\\')\">"+row.orderSn+"</a>")
                        return actions.join('');
                    }
                },
                {
                    field: 'cause',
                    title: '申请原因'
                },
                {
                    field: 'cause',
                    title: '图片',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.urls.length > 0){
                            for (var i = 0; i < row.urls.split(",").length; i++) {
                                var url = row.urls.split(",")[i];
                                actions.push('<img  src=' + url + ' style="width: 79px;height: 50px;" onclick="onLookPhotoListsClick(' + JSON.stringify(row.urls).replace(/"/g, '&quot;') + ')" />');
                            }

                        }

                        return actions.join('');
                    }
                },
                {
                    field: 'des',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="onTongGuoClick(\'' + row.id + '\')"><i class="fa fa-check-square-o"></i>通过</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="unTongGuoClick(\'' + row.id + '\')"><i class="fa fa-times "></i>驳回</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function onTongGuoClick(id) {
            var data = {
                "id": id,
                "status": 1,
                "boHuiCause": ""
            }
            $.modal.confirm("确认通过吗?", function () {
                $.operate.submit(prefix + "/shenHe", "post", "json", data, function (res) {

                });
            });
        }

        function unTongGuoClick(id) {

            layer.prompt({title: '请说明驳回原因，并确认', formType: 2}, function (text, index) {
                layer.close(index);
                var data = {
                    "id": id,
                    "status": 2,
                    "boHuiCause": text
                }
                $.operate.submit(prefix + "/shenHe", "post", "json", data, function (res) {

                });
            });
        }

        function onLookPhotoListsClick(urls) {
            var data = [];

            for (var i = 0; i < urls.split(",").length; i++) {
                data.push({"alt": "", "pid": 0, "src": urls.split(",")[i], "thumb": urls.split(",")[i]});
            }

            var json = {"title": "", "id": 1, "start": 0, "data": data};
            layer.photos({
                photos: json
                , anim: 5
            });
        }

        function goOrder(id) {
            var url = orderPrefix + "/listById/"+id;
            $.modal.openTab("订单详情", url);
        }


    </script>
</body>
</html>